using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using SqlSugar;

namespace SqlSugarEx.LambdaExtend
{
	public class DbMethodEx
	{
		public List<SqlFuncExternal> LambdaExtend()
		{
			return new List<SqlFuncExternal>
			{
				this.Round(),
				this.DateFormat(),
				this.CastTo()
			};
		}

		public virtual SqlFuncExternal Round()
		{
			return new SqlFuncExternal
			{
				UniqueMethodName = "Round",
				MethodValue = delegate(MethodCallExpressionModel expInfo, DbType dbType, ExpressionContext expContext)
				{
					int value = (int)expInfo.Args[1].MemberValue;
					if (dbType != DbType.SqlServer)
					{
						throw new Exception("未实现");
					}
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(9, 2);
					defaultInterpolatedStringHandler.AppendLiteral("ROUND(");
					defaultInterpolatedStringHandler.AppendFormatted<object>(expInfo.Args[0].MemberName);
					defaultInterpolatedStringHandler.AppendLiteral(", ");
					defaultInterpolatedStringHandler.AppendFormatted(value);
					defaultInterpolatedStringHandler.AppendLiteral(")");
					return defaultInterpolatedStringHandler.ToStringAndClear();
				}
			};
		}

		public virtual SqlFuncExternal DateFormat()
		{
			return new SqlFuncExternal
			{
				UniqueMethodName = "DateFormat",
				MethodValue = delegate(MethodCallExpressionModel expInfo, DbType dbType, ExpressionContext expContext)
				{
					int value = (int)expInfo.Args[1].MemberValue;
					int value2 = (int)expInfo.Args[2].MemberValue;
					if (dbType != DbType.SqlServer)
					{
						throw new Exception("未实现");
					}
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(24, 3);
					defaultInterpolatedStringHandler.AppendLiteral("CONVERT(nvarchar(");
					defaultInterpolatedStringHandler.AppendFormatted(value);
					defaultInterpolatedStringHandler.AppendLiteral("), ");
					defaultInterpolatedStringHandler.AppendFormatted<object>(expInfo.Args[0].MemberName);
					defaultInterpolatedStringHandler.AppendLiteral(", ");
					defaultInterpolatedStringHandler.AppendFormatted(value2);
					defaultInterpolatedStringHandler.AppendLiteral(" )");
					return defaultInterpolatedStringHandler.ToStringAndClear();
				}
			};
		}

		public virtual SqlFuncExternal CastTo()
		{
			return new SqlFuncExternal
			{
				UniqueMethodName = "CastTo",
				MethodValue = delegate(MethodCallExpressionModel expInfo, DbType dbType, ExpressionContext expContext)
				{
					string value = expInfo.Args[1].MemberValue.ToString();
					if (dbType != DbType.SqlServer)
					{
						throw new Exception("未实现");
					}
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(10, 2);
					defaultInterpolatedStringHandler.AppendLiteral("CAST(");
					defaultInterpolatedStringHandler.AppendFormatted<object>(expInfo.Args[0].MemberName);
					defaultInterpolatedStringHandler.AppendLiteral(" AS ");
					defaultInterpolatedStringHandler.AppendFormatted(value);
					defaultInterpolatedStringHandler.AppendLiteral(")");
					return defaultInterpolatedStringHandler.ToStringAndClear();
				}
			};
		}
	}
}
